package cn.est.controller;

import cn.est.dto.ModelReq;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.pojo.Model;
import cn.est.service.ModelService;
import cn.est.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api
@RestController
@RequestMapping("/api/model")
public class ModelController {

    @Autowired
    ModelService modelService;

    @ApiOperation(value = "商品的列表搜索",notes = "商品的型号列表分页显示")
    @GetMapping("/search")
    public Result list(ModelReq modelReq){

        if (modelReq.getPageNo() == null){
            modelReq.setPageNo(1);
        }

        if (modelReq.getPageSize() == null){
            modelReq.setPageSize(20);
        }

        Page<Model> modelPage = modelService.getModelPage(modelReq);
        return ResultUtils.returnDataSuccess(modelPage);

    }

    @ApiOperation(value = "商品详情",notes = "商品详情显示")
    @GetMapping("/modeldetails/{id}")
    public Result ModelDetails(@PathVariable("id") Long id){
       Model model =  modelService.getModelById(id);
       return ResultUtils.returnDataSuccess(model);

    }
}
